// DlgShowScale.cpp : implementation file
//

#include "stdafx.h"
#include "OpenCVView.h"
#include "DlgShowScale.h"
#include "afxdialogex.h"


// CDlgShowScale dialog

IMPLEMENT_DYNAMIC(CDlgShowScale, CDialog)

CDlgShowScale::CDlgShowScale(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgShowScale::IDD, pParent)
{
	m_stcscale = _T("1");
	m_numscale = 5;
}

CDlgShowScale::~CDlgShowScale()
{
}

void CDlgShowScale::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLIDER_SCALE, m_sliderscale);
	DDX_Text(pDX, IDC_STC_SCALE, m_stcscale);
}


BEGIN_MESSAGE_MAP(CDlgShowScale, CDialog)
	ON_BN_CLICKED(IDOK, &CDlgShowScale::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CDlgShowScale::OnBnClickedCancel)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER_SCALE, &CDlgShowScale::OnCustomdrawSliderScale)
END_MESSAGE_MAP()


// GetShowScale


double CDlgShowScale::GetShowScale()
{
	return _wtof(m_stcscale);
}


BOOL CDlgShowScale::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	m_sliderscale.SetRange(1,10);
	m_sliderscale.SetTicFreq(1);
	m_sliderscale.SetPos(m_numscale);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


// SetShowScale
void CDlgShowScale::SetShowScale(double scale)
{
	if(scale>1)
	{
		m_numscale = 4.0 + scale;
	}
	else
	{
		m_numscale = 5 * scale;
	}
	SetShowScale();
}
void CDlgShowScale::SetShowScale()
{
	double numdata;
	if(m_numscale>5)
	{
		numdata = (m_numscale - 4.0);
	}
	else
	{
		numdata = m_numscale/5.0;
	}
	m_stcscale.Format(_T("%0.1f"),numdata);
}


void CDlgShowScale::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
}


void CDlgShowScale::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}


void CDlgShowScale::OnCustomdrawSliderScale(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_numscale = m_sliderscale.GetPos();
	SetShowScale();
	UpdateData(FALSE); 
	*pResult = 0;
}
